// pages/logistics/logistics.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    logisticeList:[],
    expressNumber:'',//快递单号
    message:'',   //没有物流消息时的提醒信息
  },
  // 复制运单号
  copyExpressNumber(){
    var that = this
    wx.setClipboardData({
      data: that.data.expressNumber,
      success (res) {
        wx.getClipboardData({
          success (res) {
            // console.log(res.data) // data
            wx.showToast({
              title: '已复制成功',
              icon:'success'
            })
          }
        })
      }
    })
  },
  // 拨打承运人的电话
  takePhone(){
    var that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.logisticeList.phone,
      success: function () {
        // console.log("成功拨打电话")
        },
    })
  },
  // 查询物流信息
  getLogisticeList(){
    var that = this
    wx.request({
      url: getApp().globalData.baseUrl + '/wago/order/selectByLogistics',
      data: {
        expressNumber:that.data.expressNumber
      },
      method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function(res){
        // success
        console.log('res',res.data.data.list)
        if(res.data.flag){
          
          var list = res.data.data.list
          if(list.length < 1){
            that.setData({
              message:res.data.data.msg
            })
          }else{
            that.setData({
              logisticeList:res.data.data.list
            })
          }
        }
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('dataList.expressNumber',options.expressNumber)
    this.setData({
      expressNumber:options.expressNumber
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getLogisticeList()   //查询物流信息
  },
})